package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.EventInfoDto;
import com.crm.jdy.common.pojo.EventInfo;
import com.crm.jdy.common.pojo.FileManage;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.EventInfoService;
import com.crm.jdy.service.client.FileManageService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
*
* <p>说明： 文件管理API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年3月29日
*
*/
@Validated
@Api(tags = "fileManage", description = "文件管理")
@RestController
@RequestMapping("/fileManage")
public class FileManageController{

    @Reference(version = "${service.version}", check = false)
    FileManageService fileManageService;

    @RateLimit()
    @ApiOperation("文件信息")
    @PostMapping("/seleteFileManage")
    public ResultVo seleteFileManage(@RequestBody FileManage fileManage){
        List<FileManage> list = fileManageService.seleteFileManage(fileManage);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新文件信息")
    @PostMapping("/updateFileManage")
    public ResultVo updateFileManage(@ApiParam(value = "fileManage", required = true)
                                     @Validated @RequestBody FileManage fileManage){
        boolean index = fileManageService.updateFileManage(fileManage);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加文件信息")
    @PostMapping("/addFileManage")
    public ResultVo addFileManage(@ApiParam(name = "fileManage", required = false)
                                  @Validated @RequestBody FileManage fileManage){
        boolean list  = fileManageService.addFileManage(fileManage);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除文件信息")
    @DeleteMapping("deleteFileManage/{fid}")
    public ResultVo deleteFileManage(@NotNull @ApiParam(name = "fid", value = "fid", required = true) @PathVariable String fid){
        boolean b = fileManageService.removeFileManage(fid);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }





}